//
//  MMGPictureView.swift
//  MyMicroblog
//
//  Created by Mac on 17/1/7.
//  Copyright © 2017年 itcast. All rights reserved.
//

import UIKit

private let cellID: String = "pictureCellID"
class MMGPictureView: UICollectionView {

    var pictureInfos: [MMGPictureInfoDTO]? {
        didSet{
            
            self.reloadData()
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let pictureCellNib = UINib(nibName: "MMGPictureCell", bundle: nil)
        self.register(pictureCellNib, forCellWithReuseIdentifier: cellID)
        self.dataSource = self
    }
}

extension MMGPictureView: UICollectionViewDataSource {
    // 实现数据源
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return (self.pictureInfos?.count) ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! MMGPictureCell
        
        let pictureIfo = self.pictureInfos?[indexPath.item]
        cell.pictureInfo = pictureIfo
        return cell
    }
}
